home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapstair.py < prev    next >
Text File  |  2004-01-05  |  7KB  |  224 lines

  1. """   QuArK  -  Quake Army Knife Bezier shape makers
  2.  
  3.  
  4. """
  5. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  6. # FOUND IN FILE "COPYING.TXT"
  7. #
  8.  
  9. #$Header: /cvsroot/quark/runtime/plugins/mapstair.py,v 1.6 2003/04/22 11:48:03 tiglari Exp $
  10.  
  11. Info = {
  12.    "plug-in":       "Stairmaker plugin",
  13.    "desc":          "Making stairs from brushes",
  14.    "date":          "2001-02-20",
  15.    "author":        "decker",
  16.    "author e-mail": "decker@planetquake.com",
  17.    "quark":         "Version 6.3"
  18. }
  19.  
  20.  
  21. import quarkx
  22. import quarkpy.mapmenus
  23. import quarkpy.mapentities
  24. import quarkpy.mapeditor
  25. import quarkpy.mapcommands
  26. import quarkpy.mapoptions
  27. import quarkpy.maphandles
  28. import quarkpy.dlgclasses
  29. import quarkpy.mapduplicator
  30. StandardDuplicator = quarkpy.mapduplicator.StandardDuplicator
  31. from quarkpy.maputils import *
  32.  
  33. import quarkpy.mapbezier
  34. from quarkpy.b2utils import *
  35. from quarkpy.perspective import *
  36.  
  37. #
  38. #  --- Duplicators ---
  39. #
  40.  
  41. class StairDuplicator(StandardDuplicator):
  42.  
  43.   def makeStairs(self, o, steps=8, sameheight="", oldstyle=""):
  44.       result = []
  45.       #
  46.       # rebuildall() is needed in order for the pointdict function
  47.       #  below to work, when a map with the dup is loaded up
  48.       #  (treacherous bug, doesn't appear when dup is introduced
  49.       #  into map, only when it's loaded).
  50.       #
  51.       o.rebuildall()
  52.       faces = faceDict(o)
  53.       if len(faces)==6:
  54.           points = pointdict(vtxlistdict(faces,o))
  55.           frontnormal = faces['f'].normal
  56.           backnormal = faces['b'].normal
  57.           frontdist = faces['f'].dist
  58.           backdist = faces['b'].dist
  59.           frontbacklength = abs((frontnormal*frontdist) - (backnormal*backdist))
  60.           frontbackinterval = frontbacklength/steps
  61.  
  62.           upnormal = faces['u'].normal
  63.           downnormal = faces['d'].normal
  64.           updist = faces['u'].dist
  65.           downdist = faces['d'].dist
  66.           updownlength = abs((upnormal*updist) - (downnormal*downdist))
  67.           updowninterval = updownlength/steps
  68.  
  69.           for step in range(steps):
  70.               poly = quarkx.newobj("stairstep %d:p" % step)
  71.  
  72.               face = faces['l'].copy()
  73.               poly.appenditem(face)
  74.               face = faces['r'].copy()
  75.               poly.appenditem(face)
  76.  
  77.               face = faces['u'].copy()
  78.               face.translate(-upnormal * (updowninterval * (steps - step - 1)))
  79.               poly.appenditem(face)
  80.  
  81.               face = faces['d'].copy()
  82.               if sameheight != "":
  83.                  face.translate(-downnormal * (updowninterval * step))
  84.               poly.appenditem(face)
  85.               down = face
  86.  
  87.               face = faces['f'].copy()
  88.               face.translate(-frontnormal * (frontbackinterval * step))
  89.               poly.appenditem(face)
  90.  
  91.               face = faces['b'].copy()
  92.               face.translate(-backnormal * (frontbackinterval * (steps - step - 1)))
  93.               poly.appenditem(face)
  94.               back = face
  95.  
  96.               result.append(poly)
  97.               #debug('oldstyle: %s'%oldstyle)
  98.  
  99.               if sameheight!="1" and oldstyle!="1":
  100.                   #
  101.                   # the 'back' goes from the upper back of the stairstep to the
  102.                   #   lower back of the whole thing.
  103.                   # the 'down' goes from the the bottom of the visible front of the
  104.                   #   stairstep to the lower back of the whole thing
  105.                   #
  106.                   #debug('here')
  107.                   upperback = points["trb"] - backnormal * frontbackinterval * (steps - step - 1) - upnormal * (updowninterval * (steps - step - 1))
  108.                   back.setthreepoints((upperback, points["brb"], points["blb"]),0)
  109.                   lowerfront = points["trb"] - backnormal * frontbackinterval * (steps-step) - upnormal*updowninterval*(steps-step)
  110.                   down.setthreepoints((lowerfront, points["blb"], points["brb"]),0)
  111.  
  112.  
  113.       return result
  114.  
  115.   def buildimages(self, singleimage=None):
  116.     if singleimage is not None and singleimage>0:
  117.       return []
  118.     editor = mapeditor()
  119.     steps,   sameheight, oldstyle = map(lambda spec, self=self: self.dup[spec],
  120.      ("steps", "sameheight", "oldstyle"))
  121.     list = self.sourcelist()
  122.     for o in list:
  123.       if o.type==":p": # just grab the first one, who cares
  124.         return self.makeStairs(o, int(steps), sameheight, oldstyle)
  125.  
  126.  
  127. quarkpy.mapduplicator.DupCodes.update({
  128.   "dup stair":  StairDuplicator,
  129. })
  130.  
  131. #
  132. #  --- Menus ---
  133. #
  134.  
  135. def curvemenu(o, editor, view):
  136.  
  137.   def makestair(m, o=o, editor=editor):
  138.       dup = quarkx.newobj("Stair Maker:d")
  139.       dup["macro"]="dup stair"
  140.       dup["steps"]="8"
  141.       dup["sameheight"]=""
  142.       dup["oldstyle"]=""
  143.       dup.appenditem(m.newpoly)
  144.       undo=quarkx.action()
  145.       undo.exchange(o, dup)
  146.       editor.ok(undo, "make stair maker")
  147.       editor.invalidateviews()
  148.  
  149.   disable = (len(o.subitems)!=6)
  150.  
  151.   newpoly = perspectiveRename(o, view)
  152.  
  153.   def finishitem(item, disable=disable, o=o, view=view, newpoly=newpoly):
  154.       disablehint = "This item is disabled because the brush doesn't have 6 faces."
  155.       if disable:
  156.           item.state=qmenu.disabled
  157.           try:
  158.               item.hint=item.hint + "\n\n" + disablehint
  159.           except (AttributeError):
  160.               item.hint="|" + disablehint
  161.       else:
  162.           item.o=o
  163.           item.newpoly = newpoly
  164.           item.view = view
  165.  
  166.   item = qmenu.item("Stair", makestair)
  167.   finishitem(item)
  168.  
  169.   return item
  170.  
  171. #
  172. # First new menus are defined, then swapped in for the old ones.
  173. #  `im_func' returns from a method a function that can be
  174. #   assigned as a value.
  175. #
  176. def newpolymenu(o, editor, oldmenu=quarkpy.mapentities.PolyhedronType.menu.im_func):
  177.     "the new right-mouse perspective menu for polys"
  178.     #
  179.     # cf FIXME in maphandles.CenterHandle.menu
  180.     #
  181.     try:
  182.         view = editor.layout.clickedview
  183.     except:
  184.         view = None
  185.     return  [curvemenu(o, editor, view)]+oldmenu(o, editor)
  186.  
  187. #
  188. # This trick of redefining things in modules you're based
  189. #  on and importing things from is something you couldn't
  190. #  even think about doing in C++...
  191. #
  192. # It's actually warned against in the Python programming books
  193. #  -- can produce hard-to-understand code -- but can do cool
  194. #  stuff.
  195. #
  196. #
  197. quarkpy.mapentities.PolyhedronType.menu = newpolymenu
  198.  
  199.  
  200. # ----------- REVISION HISTORY ------------
  201. #$Log: mapstair.py,v $
  202. #Revision 1.6  2003/04/22 11:48:03  tiglari
  203. #fix bug that was causing stairs not to  work right when maps reloaded;
  204. #fix indentation
  205. #
  206. #Revision 1.5  2003/04/09 00:59:02  cdunde
  207. #To comment out debugs
  208. #
  209. #Revision 1.4  2003/04/08 06:07:33  cdunde
  210. #tris/overdraw-efficient fan-style stair, as suggested by foo, quakin' and Plan B
  211. #on the quake3world editing forum.  For old non-equal-height stair, use
  212. #'oldstyle' checkbox specific - by tiglari
  213. #finish needed changes to activate  'oldstyle' specific - by cdunde
  214. #
  215. #Revision 1.3  2001/03/03 19:26:59  decker_dk
  216. #Minor problem fixed.
  217. #
  218. #Revision 1.2  2001/02/14 10:08:58  tiglari
  219. #extract perspective stuff to quarkpy.perspective.py
  220. #
  221. #Revision 1.1  2001/02/04 11:52:01  decker_dk
  222. #Stair making plugin
  223. #
  224.